let http = require('http');

let server = http.createServer((req, res) => {

  // res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
  res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
  console.log(req.url);

  let url = new URL(req.url, "http://localhost:8090");
  let searchParams = url.searchParams

  // if (searchParams) {
  let data = {}
  for (let [k, v] of searchParams) {
    console.log(k, v);
    data[k] = v;
  }
  // res.write(JSON.stringify(data))
  res.write(JSON.stringify(data))
  // } else {
  //   res.write('没有请求参数');
  // }
  res.end();
})

server.listen(8090, () => {
  console.log('服务器已经启动, 端口号为8090');

});